package top.zhangjianyong.tools.validation;

import javax.validation.ConstraintValidator;
import javax.validation.ConstraintValidatorContext;

/**
 * @author zhangjianyong
 * @since 2025/4/3 上午10:53
 */
public class NumberRangeValidator implements ConstraintValidator<NumberRange, Integer> {
    private int min;
    private int max;

    @Override
    public void initialize(NumberRange constraintAnnotation) {
        min = constraintAnnotation.min();
        max = constraintAnnotation.max();
    }

    @Override
    public boolean isValid(Integer value, ConstraintValidatorContext constraintValidatorContext) {
        if (value == null) return false;
        return min <= value && value <= max;
    }
}
